package com.herui.iot.ui.main;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.herui.sdyu_lib.base.FragmentDirectionAnim;
import com.herui.sport_care.R;
import com.herui.sport_care.ui.BaseSportFragment;
import com.herui.sport_care.ui.evaluation.EvalDayFragment;
import com.herui.sport_care.ui.evaluation.EvalHistoryFragment;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * Created by amanda.shan on 2022/10/19.
 */
public class HomeFragment extends BaseSportFragment {
    @BindView(R.id.btn_eval_add)
    TextView btnEvalAdd;
    @BindView(R.id.btn_eval_history)
    TextView btnEvalHistory;
    @BindView(R.id.v_add_line)
    View vAddLine;
    @BindView(R.id.v_history_line)
    View vHistoryLine;

    EvalDayFragment evalDayFragment = EvalDayFragment.newInstance();
    EvalHistoryFragment evalHistoryFragment = EvalHistoryFragment.newInstance();

    public static HomeFragment newInstance() {
        HomeFragment fragment = new HomeFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);

        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);

        return view;
    }

    @Override
    public int getLayout() {
        return R.layout.fragment_home;
    }

    @Override
    public void initParam() {
        switchBrotherChildFragment(R.id.content, null, evalDayFragment, null);
        initBtnEval();
    }

    @OnClick({R.id.btn_eval_add, R.id.btn_eval_history})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.btn_eval_add:
                switchBrotherChildFragment(R.id.content, evalHistoryFragment, evalDayFragment,
                        new FragmentDirectionAnim(false));
                changeView(true);
                break;
            case R.id.btn_eval_history:
                switchBrotherChildFragment(R.id.content, evalDayFragment, evalHistoryFragment,
                        new FragmentDirectionAnim(true));
                changeView(false);
                break;
            default:
                break;
        }
    }
//    btn_eval按钮变换
    private void changeView(Boolean flag){
        if(flag){
            // 要加 0xff000000  rgb  ff是透明底   0x开头
            btnEvalAdd.setTextColor(0xff63E6BE);
            vAddLine.setBackgroundColor(0xff63E6BE);

            btnEvalHistory.setTextColor(0xffACACAC);
            vHistoryLine.setBackgroundColor(0xffffffff);
        }else{
            btnEvalHistory.setTextColor(0xff63E6BE);
            vHistoryLine.setBackgroundColor(0xff63E6BE);

            btnEvalAdd.setTextColor(0xffACACAC);
            vAddLine.setBackgroundColor(0xffffffff);
        }
    }
//    btn_eval按钮初始化
    private void initBtnEval(){
        btnEvalHistory.setTextColor(0xffACACAC);
        vHistoryLine.setBackgroundColor(0xffffffff);
    }
}
